package com.rabbit.eap.controller.system;

import com.rabbit.eap.framework.common.api.ApiResult;
import com.rabbit.eap.framework.common.controller.BaseController;
import com.rabbit.eap.framework.core.validator.groups.AddGroup;
import com.rabbit.eap.framework.core.validator.groups.UpdateGroup;
import com.rabbit.eap.framework.log.annotation.Module;
import com.rabbit.eap.framework.log.annotation.OperationLog;
import com.rabbit.eap.framework.log.enums.OperationLogType;
import com.rabbit.eap.system.dto.SysDictTypeDTO;
import com.rabbit.eap.system.param.SysDictTypePageParam;
import com.rabbit.eap.system.service.ISysDictTypeService;
import com.rabbit.eap.system.vo.SysDictTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @projectName: eap
 * @packageName: com.rabbit.eap.system.controller
 * @className: SysDictTypeController
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/06/06 23:05:26
 * <p>Description:
 * 字典类型表 控制器
 * </p>

 */
@Slf4j
@RestController
@RequestMapping("/system/sysDictType")
@Module("system")
@Api(value = "字典类型表API", tags = {"字典类型表"})
public class SysDictTypeController extends BaseController {

    @Autowired
    private ISysDictTypeService sysDictTypeService;


    /**
    * @Description: 添加字典类型表
    * @methodName: saveSysDictType
    * @param sysDictTypeDTO:sysDictTypeDTO数据传输对象
    * @return: ApiResult.result(flag)
    * @date: 2020/06/06 23:05:26
    * @author: rabbit
    */
    @PostMapping("/saveSysDictType")
    @RequiresPermissions("sys:dict:add")
    @OperationLog(name = "添加字典类型表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加字典类型表", response = ApiResult.class)
    public ApiResult saveSysDictType(@Validated(AddGroup.class) @RequestBody SysDictTypeDTO sysDictTypeDTO) throws Exception {
        ApiResult apiResult = sysDictTypeService.saveSysDictType(sysDictTypeDTO);
        return apiResult;
    }
    /**
     * @Description: 修改字典类型表
     * @methodName: modifySysDictType
     * @param  sysDictTypeDTO:sysDictTypeDTO数据传输对象
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @PutMapping("/modifySysDictType")
    @RequiresPermissions("sys:dict:edit")
    @OperationLog(name = "修改字典类型表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改字典类型表", response = ApiResult.class)
    public ApiResult modifySysDictType(@Validated(UpdateGroup.class) @RequestBody SysDictTypeDTO sysDictTypeDTO) throws Exception {
        ApiResult  apiResult = sysDictTypeService.modifySysDictType(sysDictTypeDTO);
        return apiResult;
    }
    /**
     * @Description: 删除字典类型表
     * @methodName: removeSysDictType
     * @param ids:id集合
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @DeleteMapping("/removeSysDictType")
    @RequiresPermissions("sys:dict:remove")
    @OperationLog(name = "删除字典类型表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除字典类型表", response = ApiResult.class)
    public ApiResult  removeSysDictType(@RequestParam("ids") Long[] ids) throws Exception {
        ApiResult  apiResult = sysDictTypeService.removeSysDictType(ids);
        return apiResult;
    }

    /**
     * @Description: 根据Id获取字典类型表详情
     * @methodName: getSysDictTypeInfo
     * @param id: id
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("/getSysDictTypeInfo")
    @RequiresPermissions("sys:dict:query")
    @OperationLog(name = "字典类型表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "字典类型表详情", response = SysDictTypeVO.class)
    public ApiResult getSysDictTypeInfo(@RequestParam("id") Long id) throws Exception {
        ApiResult apiResult = sysDictTypeService.getSysDictTypeById(id);
        return apiResult;
    }

    /**
     * @Description: 字典类型表分页列表
     * @methodName: getSysDictTypePageList
     * @param sysDictTypePageParam
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("/getSysDictTypePageList")
    @RequiresPermissions("sys:dict:list")
    @OperationLog(name = "字典类型表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "字典类型表分页列表", response = SysDictTypeVO.class)
    public ApiResult getSysDictTypePageList(SysDictTypePageParam sysDictTypePageParam) throws Exception {
        ApiResult  apiResult = sysDictTypeService.getSysDictTypePageList(sysDictTypePageParam);
        return apiResult;
    }
    /**
     * @Description: 获取所有的字典类型
     * @methodName: getAllDictType
     * @param :
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/6/13 20:48
     * @author: rabbit
     *
     */
    public ApiResult getAllDictType(){
        ApiResult apiResult = sysDictTypeService.getAllDictType();
        return apiResult;
    }

}

